/*
* @Author: Administrator
* @Date:   2018-09-08 17:58:12
* @Last Modified by:   Administrator
* @Last Modified time: 2018-09-09 15:00:23
*/
import * as constants from './constants.js';
import { fromJS } from 'immutable'
//将在immutable中一如的fromJS 抱在这个对象外面使得这个普通对象变化为一个immutable对象
const defaultState = fromJS({
  focused: false,
  list: [],
  mouseIn: false,
  page: 1,
  totalPage: 1
})
//将if用switch case做替换
export default (state = defaultState, action) => {
  switch (action.type) {
    case constants.GET_FOCUSE:
      return state.set('focused',true);
    case constants.LOSE_FOCUSE:
      return state.set('focused',false);
    case constants.CHANGE_LIST:
      return state.merge({
        list: action.data,
        totalPage: action.totalPage
      })
      // return state.set('list',action.data).set('totalPage', action.totalPage);
    case constants.CHANGE_PAGE:
      return state.set('page', action.page);
    case constants.MOUSE_ENTER:
      return state.set('mouseIn', true);
    case constants.MOUSE_LEAVE:
      return state.set('mouseIn', false);
    default:
      return state;
  }
}
//   if (action.type === constants.GET_FOCUSE) {
//     //immutable对象提供的set方法会创建一个新对象并不会直接改state里的值
//   	return state.set('focused',true);
//   }
//   if (action.type === constants.LOSE_FOCUSE) {
//   	return state.set('focused',false);
//   }
//   if (action.type === constants.CHANGE_LIST) {
//     return state.set('list',action.data);
//   }
//   return state;
// }